package fenetre;

import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import composantes.*;
import interfaces.Grille;

public class FenetreConsole {
	private int 	_largeur,
					_hauteur;
	private Grille _g;
	
	public FenetreConsole(Grille g) throws Exception{
		_largeur = g.getLargeur();
		_hauteur = g.getHauteur();
		_g = g;
	}
	
	public void afficher(){
		Cellule c;
		for(int i = 0; i < _hauteur; i++){
			for(int j = 0; j < _largeur; j++){
				c = (Cellule)_g.getElement(i, j);
				System.out.print(c.getEtat());
			}
			System.out.println();
		}
	}
	
	public void setCase(int x, int y, int etat, int type){
		
	}
	
	public void selectCase(int x, int y){
		_g.caseSelectionnee(x, y);
	}
	
	public boolean update(){
		if(_g.canUpdate()){
			_g.update();
			return true;
		}
		return false;
	}
	
	public void clear(){
		_g.clear();
	}
	
	public static void main(String[] args) throws Exception{
		Partie p = new Partie();
		p.initialiserPartie("nomPartie", 3, 5, new Dimension(10, 10));
		
		FenetreConsole f = new FenetreConsole(p.getPlaqueCellulaire());
		BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
		
		
		
		while(true){
			f.afficher();
			System.out.println("src (x y):");
			f.selectCase(b.read(), b.read());
			
			System.out.println("dst (x y):");
			f.selectCase(b.read(), b.read());
			if(!f.update())
				System.out.println("Can't update");
		}
		
	}
}
